<?php


namespace App\Http\Controllers;

use App\Http\Resources\RoleCollection;
use App\Http\Resources\UserCollection;
use App\Http\Services\UserService;
use App\Http\Traits\ApiReturn;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class UserController extends BaseController
{
    use ApiReturn;
    protected $service;
    public function __construct(Request $request,UserService $userService)
    {
        $this->service = $userService;
        $this->request = $request;
        parent::__construct($request);
    }

    public function all()
    {
        $result = $this->service->all();
        return  $result;
    }

    public function index()
    {
        $result = $this->service->list($this->request->all());
        return  $this->succ(new UserCollection($result));
    }

    public function store(){
        $result = $this->service->store($this->request->all());
        return $this->succ($result);
    }

    public function update($id){
        $result = $this->service->store($this->request->all(),$id);
        return $this->succ($result);
    }

    public function updatePassword($id){
        $result = $this->service->updatePassword($this->request->all(),$id);
        return $this->succ($result);
    }

    public function getMenuIds($id){
        $result = $this->service->getRoleMenuIds($id);
        return $this->succ($result);
    }

    public function detail($id){
        $result = $this->service->show($id);
        return $this->succ($result);

    }

    public function destroy($id){
        $result = $this->service->destroy($id);
        return $this->succ($result);
    }



}
